<?php
if($this->do=='comment'){
	check_request();
	$page_id=empty($_GET['page_id'])?0:intval($_GET['page_id']);
	$sql="SELECT * FROM ".DB_PREFIX."page_comment WHERE comment_is_display=1";
	if($page_id>0){
		$sql.=" AND page_id=$page_id";
	}
	$sql.=" AND parent_id=0 ORDER BY comment_id DESC";

	$page_size=$this->config['page_front_comment_list_size']?$this->config['page_front_comment_list_size']:10;
	$page_current=isset($_GET['page'])&&is_numeric($_GET['page'])?intval($_GET['page']):1;
	$count=$this->db->count($sql);
	$result=$this->db->result($sql." LIMIT ".(($page_current-1)*$page_size).",".$page_size);

	$array=array();
	$pager=array();
	if($count>0){
		foreach($result as $row){
			$array[$row['comment_id']]['id']=$row['comment_id'];
			$array[$row['comment_id']]['name']=$row['comment_name'];
			$array[$row['comment_id']]['content']=$row['comment_content'];
			$array[$row['comment_id']]['reply']=$row['comment_reply'];
			$array[$row['comment_id']]['email']=$row['comment_email'];
			$array[$row['comment_id']]['site']=$row['comment_site'];
			$array[$row['comment_id']]['ip']=$row['comment_ip'];
			$array[$row['comment_id']]['ip_address']=get_ip_address($row['comment_ip']);
			$array[$row['comment_id']]['agent']=$row['comment_agent'];
			$array[$row['comment_id']]['time']=date("Y/m/d H:i:s",$row['comment_time']);
		}
		$parameters="action=page&do=comment&";
		if($page_id>0){
			$parameters.="page_id=".$page_id."&";
		}
		$pager=pager(PATH.'front.php',$parameters,$page_current,$page_size,$count,'array');
	}
	$this->template->in('page_id',$page_id);
	$this->template->in('comment',$array);
	$this->template->in('count',$count);
	$this->template->in('pager',$pager);
	$this->template->out('page.comment.php');
}
if($this->do=='comment_insert'){
	check_request();
	$comment_name=empty($_GET['comment_name'])?'':addslashes(trim($_GET['comment_name']));
	$comment_email=empty($_GET['comment_email'])?'':addslashes(trim($_GET['comment_email']));
	$comment_site=empty($_GET['comment_site'])?'':addslashes(trim($_GET['comment_site']));
	$comment_content=empty($_GET['comment_content'])?'':addslashes(trim($_GET['comment_content']));
	$page_id=empty($_GET['page_id'])?0:intval($_GET['page_id']);
	$this->set_hook('front.page.comment');
	$array=array();
	$array['comment_name']=strip_tags($comment_name);
	$array['comment_email']=strip_tags($comment_email);
	$array['comment_site']=strip_tags($comment_site);
	$array['comment_content']=$comment_content;
	$array['comment_reply']='';
	$array['comment_ip']=get_ip();
	$array['comment_time']=$_SERVER['REQUEST_TIME'];
	$array['comment_agent']=addslashes($_SERVER['HTTP_USER_AGENT']);
	$array['comment_is_display']=$this->config['page_comment_moderation']==1?0:1;
	$array['page_id']=$page_id;
	$this->db->insert(DB_PREFIX."page_comment",$array);
	if($this->config['page_comment_moderation']==1){
		exit('WAIT');
	}
}
?>